package com.niiwoo.civet.account.service.local.check;

import com.niiwoo.civet.account.dto.request.AccountCheckingRecheckRequestDTO;
import com.niiwoo.civet.account.service.local.check.job.AccountCheckJobFactory;
import com.niiwoo.civet.account.service.local.check.job.apiservice.BackrollRecharge.BackrollRechargeCheckDetailServiceImpl;
import com.niiwoo.civet.account.service.local.check.job.apiservice.allbalance.AllbalanceCheckDetailServiceImpl;
import com.niiwoo.civet.account.service.local.check.job.apiservice.commission.CommissionCheckDetailServiceImpl;
import com.niiwoo.civet.account.service.local.check.job.apiservice.recharge.RechargeCheckDetailServiceImpl;
import com.niiwoo.civet.account.service.local.check.job.apiservice.withdraw.WithdrawCheckDetailServiceImpl;
import com.niiwoo.civet.account.service.local.check.job.enums.CheckFileTypeEnum;
import com.niiwoo.civet.account.service.local.check.job.properties.AccountCheckingProperties;
import com.niiwoo.civet.account.service.local.check.job.util.DateUtil;
import com.niiwoo.tripod.lanmao.properties.LanMaoProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Service;

@Service
@EnableConfigurationProperties({LanMaoProperties.class, AccountCheckingProperties.class})
public class AccountCheckingJobService extends AccountCheckJobFactory {
	@Autowired
	private LanMaoProperties lanMapProperties;
	@Autowired
	private AccountCheckingProperties accountCheckingProperties;
	
	/**
	 * 定时任务执行系统对账
	 * @param fileDate
	 */
	public void startJob(String fileDate) {
		if (fileDate == null || "".equals(fileDate))
			fileDate = DateUtil.formatCheckfileDate();
		
		start(fileDate);
	}
	
	/**
	 * 对账管理员触发重新对账
	 * @param fileDate
	 */
	public void recheckJob(AccountCheckingRecheckRequestDTO dto) {
		recheck(dto.getCheckRecordId(), dto.getCheckDate(),  dto.getReloadData() == null || dto.getReloadData() == 2  ? false : true);
	}
	
	@Override
	public void initProperties() {
		accountCheckingProperties.setPlamtformNo(lanMapProperties.getPlatformNo());
		properties = accountCheckingProperties;
	}

	@Override
	public void registry() {
		// 注册对账记录服务，实现类需要实现接口CheckRecordService
		registryCheckRecordService(AccountCheckingCheckService.class);
		// 注册通知服务，实现类需要实现接口NotifyService
		registryNotifyService(AccountCheckingCheckService.class);

		// 注册对应业务处理服务，实现类需要实现接口ParseService和接口CheckDetailService
		registryParseTask(CheckFileTypeEnum.TRANSACTION, AccountCheckingTransationService.class);
		registryParseTask(CheckFileTypeEnum.WITHDRAW, WithdrawCheckDetailServiceImpl.class);
		registryParseTask(CheckFileTypeEnum.RECHARGE, RechargeCheckDetailServiceImpl.class);
		registryParseTask(CheckFileTypeEnum.BACKROLL_RECHARGE, BackrollRechargeCheckDetailServiceImpl.class);
		registryParseTask(CheckFileTypeEnum.COMMISSION, CommissionCheckDetailServiceImpl.class);
		registryParseTask(CheckFileTypeEnum.ALLBALANCE, AllbalanceCheckDetailServiceImpl.class);
		
		registryCheckTask(CheckFileTypeEnum.TRANS_STAT, AccountCheckingTransStatService.class);
	}
	
}
